﻿<%@ Assembly Name="OfficeToolbox.SharePoint.Lists, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fc931e47448953cb" %>

<%@ Page Language="C#" Inherits="OfficeToolbox.SharePoint.Lists.FormSettings.FormSettingsPage"
    MasterPageFile="~/_layouts/application.master" Title="List Form Settings" %>

<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="wssuc" TagName="InputFormSection" Src="/_controltemplates/InputFormSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="InputFormControl" Src="/_controltemplates/InputFormControl.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="LinkSection" Src="/_controltemplates/LinkSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ButtonSection" Src="/_controltemplates/ButtonSection.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ActionBar" Src="/_controltemplates/ActionBar.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBar" Src="/_controltemplates/ToolBar.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" Src="/_controltemplates/ToolBarButton.ascx" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
    runat="server">
    <SharePoint:FormattedStringWithListType ID="FormattedStringWithListType1" runat="server"
        String="Form Settings:" LowerCase="false" />
    <a href="<%SPHttpUtility.AddQuote(SPHttpUtility.UrlPathEncode(CurrentList.DefaultViewUrl,true),Response.Output);%>">
        <%SPHttpUtility.HtmlEncode(CurrentList.Title,Response.Output);%></a>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderPageDescription" runat="server">
    Use this page to modify settings for New, Edit, and Display forms of this list.
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <SharePoint:ScriptLink ID="ScriptLink1" Name="form.js" Language="javascript" runat="server" />

    <script language="javascript">
function _spBodyOnLoad()
{
    LoadDefaults();
}

function LoadDefaults()
{
<%foreach (SPField spField in CurrentList.Fields)
{
	if (spField.Reorderable)
	{%>
	    newCol = document.getElementById("Col<%SPHttpUtility.HtmlEncode(spField.InternalName, Response.Output);%>New");
	    newCol.checked = <%if(IsChecked(spField, "New")){%>true<%}else{%>false<%}%>
	    editCol = document.getElementById("Col<%SPHttpUtility.HtmlEncode(spField.InternalName, Response.Output);%>Edit");
	    editCol.checked = <%if(IsChecked(spField, "Edit")){%>true<%}else{%>false<%}%>
	    displayCol = document.getElementById("Col<%SPHttpUtility.HtmlEncode(spField.InternalName, Response.Output);%>Display");
	    displayCol.checked = <%if(IsChecked(spField, "Display")){%>true<%}else{%>false<%}%>
    <%
    }
}
%>
}
function _spFormOnSubmit()
{
	columnsEdit = document.getElementById(<%SPHttpUtility.AddQuote(SPHttpUtility.NoEncode(HdnSelectedColsEdit.ClientID), Response.Output);%>);
	columnsDisplay = document.getElementById(<%SPHttpUtility.AddQuote(SPHttpUtility.NoEncode(HdnSelectedColsDisplay.ClientID), Response.Output);%>);
	columnsNew = document.getElementById(<%SPHttpUtility.AddQuote(SPHttpUtility.NoEncode(HdnSelectedColsNew.ClientID), Response.Output);%>);
	columnNames = document.getElementById(<%SPHttpUtility.AddQuote(SPHttpUtility.NoEncode(HdnColNames.ClientID), Response.Output);%>);
<%
foreach (SPField spField in CurrentList.Fields)
{
	if (!spField.Reorderable)
	{
		continue;
	}
%>
	newCol = document.getElementById("Col<%SPHttpUtility.HtmlEncode(spField.InternalName, Response.Output);%>New");
	editCol = document.getElementById("Col<%SPHttpUtility.HtmlEncode(spField.InternalName, Response.Output);%>Edit");
	displayCol = document.getElementById("Col<%SPHttpUtility.HtmlEncode(spField.InternalName, Response.Output);%>Display");
	columnsEdit.value += editCol.checked ? "1" : "0";
	columnsDisplay.value += displayCol.checked ? "1" : "0";
	columnsNew.value += newCol.checked ? "1" : "0";
	columnNames.value += "<%SPHttpUtility.HtmlEncode(spField.InternalName, Response.Output);%>,";
<%
}
%>
	elts = document.forms.<%SPHttpUtility.NoEncode(Form.ClientID, Response.Output);%>;
	for (i = 0; i < elts.length; i++)
	{
		elts[i].disabled = false;
	}
	return true;
}

    function SetDefaults()
{
<%
foreach (SPField spField in CurrentList.Fields)
{
	if (spField.Reorderable)
	{
%>
	newElt = document.getElementById("Col<%SPHttpUtility.EcmaScriptStringLiteralEncode(spField.InternalName, Response.Output);%>New");
	editElt = document.getElementById("Col<%SPHttpUtility.EcmaScriptStringLiteralEncode(spField.InternalName, Response.Output);%>Edit");
	displayElt = document.getElementById("Col<%SPHttpUtility.EcmaScriptStringLiteralEncode(spField.InternalName, Response.Output);%>Display");
	if (!newElt.checked)
	{
		newElt.click();
	}
	if (!editElt.checked)
	{
		editElt.click();
	}
	if (!displayElt.checked)
	{
		displayElt.click();
	}
<%
	}
}
%>}
    </script>

</asp:Content>
<asp:Content ID="ContentMain" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <table class="ms-propertysheet" border="0" width="100%" cellspacing="0" cellpadding="0">
        <!-- Columns: New -->
        <wssuc:InputFormSection id="ColumnsNewSection" Title="Form Fields" Description="Select columns for availability across form types in the list."
            runat="server">
            <template_inputformcontrols>
		<wssuc:InputFormControl runat="server">
			<Template_Control>
				<table border="0" width="100%" cellspacing="0" cellpadding="2">
				<tr>
					<th scope="col" class="ms-authoringcontrols" valign="top">
						<B><SharePoint:EncodedLiteral runat="server" text="Column" EncodeMethod='HtmlEncode'/></B>
					</th>
					<th scope="col" class="ms-authoringcontrols" style="text-align:center; width:50px;" valign="top"><b>New</b></th>
					<th scope="col" class="ms-authoringcontrols" style="text-align:center; width:50px;" valign="top"><b>Edit</b></th>
					<th scope="col" class="ms-authoringcontrols" style="text-align:center; width:50px;" valign="top"><b>Display</b></th>
				</tr>
<%
SPFieldCollection listFields = CurrentList.Fields;
ArrayList spOrderedFields = SortFields(listFields,CurrentList.ParentWeb.Locale);
int numFieldsDisplayed = 0;
int curFieldIndex = 0;

for (int i = 0; i < listFields.Count; i++) {
    SPField spField = listFields.GetFieldByInternalName(listFields[i].InternalName);
    if (spField.Reorderable){
	%>
				<TR>
					<TD class="ms-authoringcontrols" valign="top">
						 <LABEL for="Col<%SPHttpUtility.HtmlEncode(spField.InternalName, Response.Output);%>New"><%SPHttpUtility.HtmlEncode(listFields[i].Title, Response.Output);%></LABEL>
					</TD>
					<TD class="ms-authoringcontrols"style="text-align:center" valign="top">
						<INPUT type="checkbox" id="Col<%SPHttpUtility.HtmlEncode(spField.InternalName, Response.Output);%>New" checked/>
					</TD>
					<TD class="ms-authoringcontrols"style="text-align:center" valign="top">
						<INPUT type="checkbox" id="Col<%SPHttpUtility.HtmlEncode(spField.InternalName, Response.Output);%>Edit" checked/>
					</TD>
					<TD class="ms-authoringcontrols"style="text-align:center" valign="top">
						<INPUT type="checkbox" id="Col<%SPHttpUtility.HtmlEncode(spField.InternalName, Response.Output);%>Display" checked/>
					</TD>
				</TR>
<%
}
}
%>				</table>
			</Template_Control>
			</wssuc:InputFormControl>
	</template_inputformcontrols>
        </wssuc:InputFormSection>
        <input type="hidden" id="HdnSelectedColsDisplay" value="" runat="server" />
        <input type="hidden" id="HdnSelectedColsEditRead" value="" runat="server" />
        <input type="hidden" id="HdnSelectedColsEdit" value="" runat="server" />
        <input type="hidden" id="HdnSelectedColsNew" value="" runat="server" />
        <input type="hidden" id="HdnColNames" value="" runat="server" />
        <!-- Button section -->
        <wssuc:ButtonSection runat="server">
            <template_buttons>
		<INPUT type="button" id="BtnDefaults" onclick="SetDefaults()" value="<%$Resources:wss,listsyndication_button_defaults%>" class="ms-ButtonHeightWidth" runat="server"/>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<asp:Button UseSubmitBehavior="false" runat="server" class="ms-ButtonHeightWidth" OnClick="ApplySettings" Text="<%$Resources:wss,listsyndication_button_ok%>" id="BtnApply" accesskey="<%$Resources:wss,listsyndication_button_ok_accesskey%>"/>
	</template_buttons>
        </wssuc:ButtonSection>
    </table>
</asp:Content>
